/**
 * 
 */
package com.cipe.cmrs.controllers;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.cipe.cmrs.model.Organizationtype;
import com.cipe.cmrs.service.OrganizationtypeService;

/**
 * @author Incepio
 *
 */
@Controller
public class OrganizationtypeController extends BaseController {

	/**
	 * 
	 */
	private static final long		serialVersionUID	= -3823562098119817733L;
	@Autowired
	private OrganizationtypeService	organizationtypeService;

	@RequestMapping("/secure/saveOrganizationtype.do")
	public String SaveOrganizationtype(@ModelAttribute("organizationtype") Organizationtype organizationtype, BindingResult result, Model model, HttpServletRequest request) {
		try {
			organizationtype = organizationtypeService.saveOrganizationtype(organizationtype, getUserId(request));
			saveMessage(request, getText("editOrganizationtype.message.success"));
		} catch (Exception e) {
			logger.error(getText("error.transaction"), e);
			saveError(request, getText("error.transaction"));
		}
		model.addAttribute("organizationtype", organizationtype);
		return "editOrganizationtype";
	}

	@RequestMapping("/secure/showAddOrganizationtype.do")
	public String showAddOrganizationtype(Model model) {
		model.addAttribute("organizationtype", new Organizationtype());
		return "editOrganizationtype";
	}

	@RequestMapping("/secure/showEditOrganizationtype.do")
	public String showEditOrganizationtype(@RequestParam Integer id, Model model) {
		model.addAttribute("organizationtype", organizationtypeService.findById(id));
		return "editOrganizationtype";
	}

	@RequestMapping("/secure/showOrganizationtypeList.do")
	public String showOrganizationtypeList(Model model) {
		model.addAttribute("organizationtypes", organizationtypeService.findAll());
		return "organizationtypeList";
	}
}
